/**
 * 
 */
package com.ingesup.dao;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.ingesup.entities.Contact;

/**
 * @author FDEJEAN
 *
 */
public class ContactDaoTest {

	private static ContactDao dao;
	private static Contact user;
	
	@Before
	public void beforeTest() {
		dao = new ContactDaoImpl(Contact.class);		
	}
	
	@Test
	public void testCreate() {
		Contact temp = new Contact();
		temp.setNom("wistiti");
		temp.setAdresseMail("florian.dejean@gmail.com");
		Contact temp2 = dao.create(temp);
		assertNotNull(temp2);
		assertTrue(temp2.getId() > 0);
	}

	
	@Test
	public void testReadAll() {
		List<Contact> tempList = new ArrayList<Contact>();
		tempList = dao.getAll();
		assertEquals(1, tempList.size());
		user = tempList.get(0);
	}
	
	
	@Test
	public void testRead() {
		Contact temp = dao.read(user.getId());
		assertNotNull(temp);
		assertNotNull(temp.getNom());
	}

	
	@Test
	public void testUpdate() {
		Contact temp = dao.read(user.getId());
		temp.setNom("Nounouille");
		dao.update(temp);
		
		temp = dao.read(user.getId());
		assertEquals("Nounouille", temp.getNom());
	}

	
	@Test
	public void testDelete() {
		dao.delete(user);
		assertEquals(0, dao.getAll().size());
	}
}